﻿/* 
 * yaku
 * http://code.google.com/p/yaku/
 * 
 * Copyright 2011, Bryan McKelvey
 * Licensed under the MIT license
 * http://www.opensource.org/licenses/mit-license.php
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace yaku
{
    public partial class Edict
    {
        /// <summary>
        /// An entry in the EDICT dictionary.
        /// </summary>
        private class EdictEntry
        {
            private List<string> english = new List<string>();
            private List<string> kanji = new List<string>();
            private List<string> furigana = new List<string>();
            private string searchText;

            public EdictEntry()
            {
            }

            public void Close()
            {
                StringBuilder builder = new StringBuilder("|");
                foreach (string value in english)
                {
                    builder.Append(value.Replace(", ", "|")).Append('|');
                }
                foreach (string value in kanji)
                {
                    builder.Append(value).Append('|');
                }
                foreach (string value in furigana)
                {
                    builder.Append(value).Append('|');
                }
                searchText = builder.ToString();
            }

            #region Properties
            /// <summary>
            /// The English for the entry.
            /// </summary>
            public string English
            {
                get { return string.Join(", ", english); }
            }

            /// <summary>
            /// The kanji for the entry.
            /// </summary>
            public string Kanji
            {
                get { return string.Join("、", kanji); }
            }

            /// <summary>
            /// The furigana for the entry.
            /// </summary>
            public string Furigana
            {
                get { return string.Join("、", furigana); }
            }

            /// <summary>
            /// The Hepburn transliteration for the furigana.
            /// </summary>
            public string Romaji
            {
                get { return Transliterator.Romanize(furigana); }
            }

            /// <summary>
            /// The English list for the entry.
            /// </summary>
            public List<string> EnglishList
            {
                get { return english; }
                set { english = value; }
            }

            /// <summary>
            /// The kanji list for the entry.
            /// </summary>
            public List<string> KanjiList
            {
                get { return kanji; }
                set { kanji = value; }
            }

            /// <summary>
            /// The furigana list for the entry.
            /// </summary>
            public List<string> FuriganaList
            {
                get { return furigana; }
                set { furigana = value; }
            }

            /// <summary>
            /// The text for searching via LINQ.
            /// </summary>
            public string SearchText
            {
                get { return searchText; }
            }
            #endregion
        }
    }
}
